/***************************************************************
Copyright ? wq Co., Ltd. 1998-2099. All rights reserved.
文件名	   : CySysKey.c
版本	   : V0.0
描述	   : CWP085 master 测试应用案例。
其他	   : 无
日志	   : 初版V0.0 2025/01/17 
***************************************************************/

/*******************************************************************************
* Include 
*******************************************************************************/ 
#include "CySysMaster.h"






/*******************************************************************************
* Function Name  : WriteCommandPacket
* Description    : commd write
* Input          : wrData    :read register addr          cnt: read register addr length
                   mode      :I2C_A_I2C_MODE_COMPLETE_XFER
* Output         : None
* Return         : None
*******************************************************************************/


void WriteCommandPacket(uint32 slaveAddress, uint8 * wrData, uint32 cnt, uint32 mode)
{
    
    (void) I2C_I2CMasterClearStatus();
    
    /* Start I2C write and check status*/
    if(I2C_I2C_MSTR_NO_ERROR == I2C_I2CMasterWriteBuf(slaveAddress,wrData, cnt,mode))
    {
        /*If I2C write started without errors, 
        / wait until I2C Master completes write transfer 
        */
        while (0u == (I2C_I2CMasterStatus() &I2C_I2C_MSTAT_WR_CMPLT))
        {
            /* Wait */
        }
        
    }
}

/*******************************************************************************
* Function Name  : WriteCommandPacket
* Description    : commd write
* Input          : readdata  :sotre read data buff       r_length:read data length
                   mode      :I2C_A_I2C_MODE_COMPLETE_XFER
* Output         : None
* Return         : None
*******************************************************************************/
void ReadStatusPacket(uint32 slaveAddress, uint8 * rdData, uint32 cnt, uint32 mode)
{  
    (void) I2C_I2CMasterClearStatus();
    
    if(I2C_I2C_MSTR_NO_ERROR ==  I2C_I2CMasterReadBuf(slaveAddress,rdData, cnt,mode))
    {
        /* If I2C read started without errors, 
        / wait until master complete read transfer */
        while (0u == (I2C_I2CMasterStatus() & I2C_I2C_MSTAT_RD_CMPLT))
        {
            /* Wait */
        }
        
    }
}







